package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CompanyCategroy;
import com.ruoyi.system.service.ICompanyCategroyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商家商品分类Controller
 * 
 * @author ruoyi
 * @date 2025-08-20
 */
@RestController
@RequestMapping("/system/companyCategroy")
public class CompanyCategroyController extends BaseController
{
    @Autowired
    private ICompanyCategroyService companyCategroyService;

    /**
     * 查询基础分类树
     */
    @RequestMapping("/getJsonData")
    public AjaxResult getJsonData()
    {
        CompanyCategroy companyCategroy = new CompanyCategroy();
        companyCategroy.setCompanyId(getCompanyId());
        AjaxResult ajax = companyCategroyService.getJsonData(companyCategroy);
        return ajax;
    }


    /**
     * 查询商家商品分类列表
     */
    @PreAuthorize("@ss.hasRole('company')")
    @GetMapping("/list")
    public TableDataInfo list(CompanyCategroy companyCategroy)
    {
        startPage();
        companyCategroy.setCompanyId(getCompanyId());
        List<CompanyCategroy> list = companyCategroyService.selectCompanyCategroyList(companyCategroy);
        return getDataTable(list);
    }

    /**
     * 导出商家商品分类列表
     */
    @PreAuthorize("@ss.hasRole('company')")
    @Log(title = "商家商品分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CompanyCategroy companyCategroy)
    {
        companyCategroy.setCompanyId(getCompanyId());
        List<CompanyCategroy> list = companyCategroyService.selectCompanyCategroyList(companyCategroy);
        ExcelUtil<CompanyCategroy> util = new ExcelUtil<CompanyCategroy>(CompanyCategroy.class);
        util.exportExcel(response, list, "商家商品分类数据");
    }

    /**
     * 获取商家商品分类详细信息
     */
    @PreAuthorize("@ss.hasRole('company')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(companyCategroyService.selectCompanyCategroyById(id));
    }

    /**
     * 新增商家商品分类
     */
    @PreAuthorize("@ss.hasRole('company')")
    @Log(title = "商家商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompanyCategroy companyCategroy)
    {
        companyCategroy.setCompanyId(getCompanyId());
        return toAjax(companyCategroyService.insertCompanyCategroy(companyCategroy));
    }

    /**
     * 修改商家商品分类
     */
    @PreAuthorize("@ss.hasRole('company')")
    @Log(title = "商家商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompanyCategroy companyCategroy)
    {
        companyCategroy.setCompanyId(getCompanyId());
        return toAjax(companyCategroyService.updateCompanyCategroy(companyCategroy));
    }

    /**
     * 删除商家商品分类
     */
    @PreAuthorize("@ss.hasRole('company')")
    @Log(title = "商家商品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(companyCategroyService.deleteCompanyCategroyByIds(ids));
    }
}
